package com.sgcc.ln.pmos.common.utils;

import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sgcc.ln.pmos.arouter.app.AppArouterPath;
import com.sgcc.ln.pmos.common.bean.UserBean;
import com.sgcc.ln.pmos.common.interceptor.SignInterceptor;

public class UserManager {

    private static UserBean mUserBean = null;

    public static UserBean getUserBean() {
        if (mUserBean == null) {
            mUserBean = new UserBean();
        }
        return mUserBean;
    }

    public static void setUserBean(UserBean userBean) {
        mUserBean = userBean;
    }

    public static boolean isLogin() {
        boolean isLogin = false;
        if (mUserBean != null && mUserBean.getExtend() != null && !TextUtils.isEmpty(mUserBean.getExtend().getTicket())) {
            isLogin = true;
        }
        return isLogin;
    }

    public static boolean toLogin() {
        if (!isLogin()) {
            ARouter.getInstance()
                    .build(AppArouterPath.APP_LOGIN)
                    .navigation();

        }
        return isLogin();
    }

    /**
     * 退出交易账号
     */
    public static void logout() {
        PackageContrastUtils.clear();
        SignInterceptor.Authorization = "";
        mUserBean = null;
    }
}
